﻿using Avalonia.Controls;
using Avalonia.Platform;

namespace Bread.Mvc.Avalonia;

public class VideoHost : NativeControlHost
{
    public event Action? HwndCreated;

    public nint Hwnd { get; private set; } = nint.Zero;

    public VideoHost()
    {
    }

    protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent)
    {
        var handle = base.CreateNativeControlCore(parent);
        Hwnd = handle.Handle;
        HwndCreated?.Invoke();
        return handle!;
    }

    protected override void DestroyNativeControlCore(IPlatformHandle control)
    {
        Hwnd = nint.Zero;
        base.DestroyNativeControlCore(control);
    }
}